﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Irony.Ast;
using Irony.Parsing;

namespace AppServidor
{
    class sintacticoListas:Grammar
    {
       public sintacticoListas() { 
            StringLiteral cad = TerminalFactory.CreateCSharpString("cad");
            IdentifierTerminal id = TerminalFactory.CreateCSharpIdentifier("id");
            CommentTerminal escape = new CommentTerminal("escape","\r\n", "\r");
            base.NonGrammarTerminals.Add(escape);
        
          NonTerminal   LGL = new NonTerminal("LGL"),
           LR = new NonTerminal("LR"),
                        A = new NonTerminal("A"),
                        LA = new NonTerminal("LA"),
                        LP = new NonTerminal("LP"),
                        Val = new NonTerminal("Val"),
          L = new NonTerminal("L");

          L.Rule = L+ ToTerm("{") +  ToTerm("grupo_listas") + ToTerm(":") + ToTerm("[") +Eos+ Indent + LGL +Eos+ Dedent + ToTerm("]") + ToTerm("}")+Eos
                    |L +ToTerm("{")+ToTerm("lista")+ToTerm(":") +Eos + Indent + ToTerm("{") + LA +Eos+ ToTerm("}") + Eos+Dedent + ToTerm("}")+Eos
                    |ToTerm("{") +  ToTerm("grupo_listas") + ToTerm(":") + ToTerm("[") +Eos+ Indent + LGL +Eos+ Dedent + ToTerm("]") + ToTerm("}")+Eos
                    |ToTerm("{")+ToTerm("lista")+ToTerm(":") +Eos + Indent + ToTerm("{") + LA +Eos+ ToTerm("}") + Eos+Dedent + ToTerm("}")+Eos;
           
           
           LGL.Rule = LGL + ToTerm(",")+Eos + LR
                | LR;

           LR.Rule = ToTerm("{")+ToTerm("lista")+ToTerm(":") +Eos + Indent + ToTerm("{") + LA +Eos+ ToTerm("}") + Eos+Dedent + ToTerm("}");

            LA.Rule = LA + ToTerm(",")+Eos + A
                | A;

            A.Rule = ToTerm("nombre")+ToTerm(":") + cad
               | ToTerm("random")+ToTerm(":") + Val
               | ToTerm("circular")+ToTerm(":") + Val
               | ToTerm("pistas")+ToTerm(":") + ToTerm("[") + LP + ToTerm("]");

            LP.Rule = LP + ToTerm(",") + id
              | id;

            Val.Rule = ToTerm("true")
               | ToTerm("false");

            this.Root = L;

        }

       public override void CreateTokenFilters(LanguageData language, TokenFilterList filters)
       {
           var outlineFilter = new CodeOutlineFilter(language.GrammarData,
             OutlineOptions.ProduceIndents | OutlineOptions.CheckBraces, ToTerm(@"\")); // "\" is continuation symbol
           filters.Add(outlineFilter);
       }
    }
}
